package com.lex.kpg;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import com.lex.activitytext.R;

import java.util.List;

/**
 * Created by Administrator on 2016/7/4.
 */
public class TestKpgActivity extends Activity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_contact);
    }

    public void chooseContact(View view){
        List<ResolveInfo> browsers = getLocalBrowsers(this);
        if (browsers != null && browsers.size() > 0){
            Intent intent = new Intent();
            intent.setPackage(browsers.get(0).activityInfo.packageName);
            intent.setData(Uri.parse("http://www.baidu.com"));
            startActivity(intent);
        }
    }

    public static List<ResolveInfo> getLocalBrowsers(Context context){
        //adb shell am start -a android.intent.action.VIEW http://www.baidu.com
        //adb shell am start -n com.lex.kpg/com.lex.kpg.TestHandlerActivity

        Intent intent = new Intent();
        intent.addCategory(Intent.CATEGORY_BROWSABLE);
        intent.setData(Uri.parse("http://"));
        List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER);
        return list;
    }

    public static List<ResolveInfo> getLocalShares(Context context){

        Intent intent = new Intent();
        intent.addCategory(Intent.ACTION_SEND);
        intent.setType("text/plain");
        List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER);
        return list;
    }
}
